<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>大事件-后台登录</title>
    <link rel="stylesheet" href="./css/reset.css">
    <!-- 1.0 导入bootstrap样式 -->
    <link rel="stylesheet" href="./libs/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="./css/login.css">
</head>

<body>
    <!--container 是bootstrap的父容器  -->
    <div class="container">
        <!-- logo -->
        <img class="logo" src="./images/logo.png" alt="">

        <!-- 登录框-panel是bootstrap中的面板  -->
        <div class="panel panel-success">
            <div class="panel-heading">
                <h3 class="panel-title"></h3>
            </div>
            <div class="panel-body">
                <!-- 登录框表单 form-horizontal 是bootstrap中的水平方向的表单 -->
                <form id="login_form" class="form-horizontal">
                    <div class="form-group">
                        <div class="col-sm-12 item">
                            <input type="text" class="form-control" id="username" name="username" placeholder="请输入用户名" required>
                            <!-- 用户图标 -->
                            <i class="glyphicon glyphicon-user"></i>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-12 item">
                            <input type="password" class="form-control" id="password" name="password" required placeholder="请输入密码">
                            <!-- 密码图标 -->
                            <i class="glyphicon glyphicon-lock"></i>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-12">
                            <button type="submit" id="login" class="btn btn-success btn-block">登录</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>

    </div>
    <script src="./libs/jquery/jquery.min.js">
    </script>
    <script src="./libs/layui/layui.js"></script>
    <script>
        //
        $(function() {
            let layer;
            layui.use('layer', function() {
                layer = layui.layer;
                // layer.msg('提示数据')
            });
            $('#login_form').submit(function(e) {
                e.preventDefault()
                let username = $('#username').val().trim()
                let password = $('#password').val().trim()
                    // console.log(username, password);
                $.ajax({
                    type: 'post',
                    url: 'http://localhost:8080/api/v1/admin/user/login',
                    data: {
                        username,
                        password
                    },
                    success: (res) => {
                        console.log(res)
                        if (res.code == 200) {
                            // alert('密码或者用户名错误')
                            layer.msg('登录成功', {
                                icon: 1,
                                time: 1000 //2秒关闭（如果不配置，默认是3秒）
                            }, function() {
                                //do something
                                location.href = './index.html'
                                localStorage.setItem('token64', res.token);

                            });
                            return
                        } else {
                            layer.msg('密码或者用户名错误', {
                                icon: 2,
                                time: 500 //2秒关闭（如果不配置，默认是3秒）
                            }, function() {
                                //do something  
                                let password = $('#password').val('')
                                let username = $('#username').val('')
                            });
                        }
                        // 2.0 跳转到首页

                    },
                })


                // console.log(username, password);
            })
        })
    </script>





</body>

</html>